package com.lex.crossgate.admin.modules.sys.service.imp;

import com.lex.crossgate.common.constants.Constant;
import com.lex.crossgate.common.constants.R;;
import com.lex.crossgate.admin.modules.sys.dao.SysRoleDao;
import com.lex.crossgate.admin.modules.sys.entity.SysRole;
import com.lex.crossgate.admin.modules.sys.service.SysRoleService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * java类简单作用描述
 *
 * @ProjectName: crossgate
 * @Package: com.lex.crossgate.admin.modules.sys.service.imp
 * @ClassName: ${TYPE_NAME}
 * @Description: java类作用描述
 * @Author: 李贝留斯
 * @CreateDate: 2018/5/2 15:55
 * @Version: 1.0
 **/
@Service("SysRoleService")
public class SysRoleServiceImpl implements SysRoleService{

    @Autowired
    private SysRoleDao sysRoledao;

    /**
     * @description: 保存用户
     * @author 李贝留斯
     * @email sunyadongsyd@163.com
     * @date 2018/5/10 22:45
     */
    public R save(SysRole SysRole) {
        int row = sysRoledao.insert(SysRole);

        if(row>0){
           return R.ok(Constant.SYSUSER);
        }else {
            return R.error(Constant.ERROR);
        }
    }

    @Override
    public R delete(String ids) {
        String[] id = ids.split(",");
        for(int i=0;i<id.length;i++){
            sysRoledao.deleteById(id[i]);
        }
        return R.ok(Constant.SUCCESS);
    }

    @Override
    public R update(SysRole SysRole) {
        int row = sysRoledao.updateById(SysRole);
        if(row>0){
            return R.ok(Constant.SUCCESS);
        }else {
            return R.error(Constant.ERROR);
        }
    }

    /**
     * @description: 获取用户列表
     * @author 李贝留斯
     * @date 2018/5/8 21:30
     */
    public List<SysRole> getSysRole(String roleName,String roleSign) {
        EntityWrapper entityWrapper = new EntityWrapper();
        if (StringUtils.isNotEmpty(roleName))
            entityWrapper.like("role_name",roleName);
        if (StringUtils.isNotEmpty(roleSign))
            entityWrapper.like("role_sign",roleSign);
        List<SysRole> roleList = sysRoledao.selectList(entityWrapper);
        return roleList;
    }

    public SysRole getRoleById(String id) {
        SysRole SysRole = sysRoledao.selectById(id);
        return SysRole;
    }

}
